<?
if (!defined('MODULE_FILE')){
die ("cant access file directly!");
}

$mid 	= ( ( true == isset( $_GET['mid'] ) && true == valStr( $_GET['mid'] ) ) ? $_GET['mid'] : NULL );
$smid 	= ( ( true == isset( $_GET['smid'] ) && true == valStr( $_GET['smid'] ) ) ? $_GET['smid'] : NULL );

autoLoader();

$objBaseHospital 	= new BaseHospital();
$objHospital 		= new Hospital();
?>
<html>
<head>
<?php require_once 'commonJS.php'; ?>
</head>
<body>
<br>
<div class="col-lg-8">
<div class="panel panel-primary">
<div class="panel-heading"><i class="fa fa-bell fa-fw"></i>Hospital Details</div>
<div class="panel-body">
	<form METHOD="POST" action="modules.php?file=insert_hospital&type=insert&mid=<? echo $mid; ?>&smid=<? echo $smid; ?>" id="formSubmit" name="formSubmit" >
			
			<?php
				$intHospitalId 		= NULL;
				$strName = NULL;
				$strDescription= NULL;
				$strAddressLine1= NULL;
				$strAddressLine2= NULL;
				$strAddressLine3= NULL;
				$strArea= NULL;
				$strCity= NULL;
				$strPinCode= NULL;
				$strAddressDetails= NULL;
				$strPrimaryPhoneNumber= NULL;
				$strEmailAddress= NULL;
				$strWebUrl= NULL;
				$strAlternativeNumber= NULL;
				
				if( true == isset( $_GET['hospital_id'] ) && true == valStr( $_GET['hospital_id'] ) ) {
					$intHospitalId = $_GET['hospital_id'];
					
					$objBaseHospital = $objHospital->fetchHospitalById( $intHospitalId );
					
					if( true == valObj( $objBaseHospital, 'BaseHospital' ) ) {
						$intHospitalId 		    = $objBaseHospital->getId();
						$strName 		        = $objBaseHospital->getName();
						$strDescription 		= $objBaseHospital->getDescription();
						$strAddressLine1 		= $objBaseHospital->getAddressLine1();
						$strAddressLine2 		= $objBaseHospital->getAddressLine2();
						$strAddressLine3 		= $objBaseHospital->getAddressLine3();
						$strArea 			    = $objBaseHospital->getArea();
						$strCity 	            = $objBaseHospital->getCity();
						$strPinCode 	        = $objBaseHospital->getPinCode();
						$strAddressDetails 		= $objBaseHospital->getAddressDetails();
						$strPrimaryPhoneNumber 	= $objBaseHospital->getPrimaryPhoneNumber();
						$strEmailAddress 	    = $objBaseHospital->getEmailAddress();
						$strWebUrl 	            = $objBaseHospital->getWebUrl();
						$strAlternativeNumber 	= $objBaseHospital->getAlternativeNumber();
						
					}
				} else if( true == valObj( $objBaseHospital, 'BaseHospital' ) ) {
					$intHospitalId = $objBaseHospital->fetchNextId();
				}
			?>
	
	
		<table width="80%" cellspacing="0" cellpadding="3">
			<tr><td height="10" colspan="2"><input type="hidden" id="hospital_id" Name="hospital_id" value="<?php echo $intHospitalId;?>"></td></tr>
			<tr valign="top">
				<td class="mandatory" width="220">Name</td>
				<td><input id="name" Name="name" type="text" class="validate[required]" style="width:402px;" value="<?php echo $strName;?>"></td>
			</tr>
			<tr><td height="10" colspan="2"></td></tr>
			<tr valign="top">
				<td class="desc" width="220">Description</td>
				<td><textarea name="description" rows="2" cols="50"><?php echo $strDescription;?></textarea></td>
			</tr>
			<tr><td height="10" colspan="2"></td></tr>
			<tr valign="top">
				<td class="desc" width="220">Address1</td>
				<td><textarea name="address_line1" rows="2" cols="50"><?php echo $strAddressLine1;?></textarea></td>
			</tr>
			<tr><td height="10" colspan="2"></td></tr>
			<tr valign="top">
				<td class="desc" width="220">Address2</td>
				<td><textarea name="address_line2" rows="2" cols="50"><?php echo $strAddressLine2;?></textarea></td>
			</tr>
			<tr><td height="10" colspan="2"></td></tr>
			<tr valign="top">
				<td class="desc" width="220">Address3</td>
				<td><textarea name="address_line3" rows="2" cols="50"><?php echo $strAddressLine3;?></textarea></td>
			</tr>
			<tr><td height="10" colspan="2"></td></tr>
			<tr valign="top">
				<td class="mandatory" width="220">Area</td>
				<td><input id="area" Name="area" type="text" class="validate[required]" style="width:202px;" value="<?php echo $strArea;?>"></td>
			</tr>
			<tr><td height="10" colspan="2"></td></tr>
			<tr valign="top">
				<td class="mandatory" width="220">City</td>
				<td><input id="city" Name="city" type="text" class="validate[required]" style="width:202px;" value="<?php echo $strCity;?>"></td>
			</tr>
			<tr><td height="10" colspan="2"></td></tr>
			<tr valign="top">
				<td class="mandatory" width="220">Pin Code</td>
				<td><input id="pin_code" Name="pin_code" type="text" class="validate[required]" style="width:202px;" value="<?php echo $strPinCode;?>"></td>
			</tr>
			<tr><td height="10" colspan="2"></td></tr>
			<tr valign="top">
				<td class="mandatory" width="220">Address Details</td>
				<td><input id="address_details" Name="address_details" type="text" class="validate[required]" style="width:202px;" value="<?php echo $strAddressDetails;?>"></td>
			</tr>
			<tr><td height="10" colspan="2"></td></tr>
			<tr valign="top">
				<td class="mandatory" width="220">Primary Phone</td>
				<td><input id="primary_phone_number" Name="primary_phone_number" type="text" class="validate[required]" style="width:202px;" value="<?php echo $strPrimaryPhoneNumber;?>"></td>
			</tr>
			<tr><td height="10" colspan="2"></td></tr>
			<tr valign="top">
				<td class="mandatory" width="220">Email</td>
				<td><input id="email_address" Name="email_address" type="text" class="validate[required]" style="width:202px;" value="<?php echo $strEmailAddress;?>"></td>
			</tr>
		   <tr><td height="10" colspan="2"></td></tr>
			<tr valign="top">
				<td class="mandatory" width="220">Web URL</td>
				<td><input id="web_url" Name="web_url" type="text" class="validate[required]" style="width:202px;" value="<?php echo $strWebUrl;?>"></td>
			</tr>
			<tr><td height="10" colspan="2"></td></tr>
			<tr valign="top">
				<td class="mandatory" width="220">Alternative Phone</td>
				<td><input id="alternative_number" Name="alternative_number" type="text" class="validate[required]" style="width:202px;" value="<?php echo $strAlternativeNumber;?>"></td>
			</tr>
			<tr><td height="10" colspan="2"></td></tr>
			<tr valign="top">
				<td class="mandatory" width="220">&nbsp;</td>
				<td>
				<?php
					if( true == isset( $_GET['hospital_id'] ) && true == valStr( $_GET['hospital_id'] ) ) {
						echo "<input type=hidden name=operation value=update>";
						echo "<input type=submit value=UPDATE id=Submit name=Submit>";
					} else {
						echo "<input type=hidden name=operation value=insert>";
						echo "<input type=submit value=SUBMIT id=Submit name=Submit>";
					}
				?>
				<a href="modules.php?file=view_patients&type=view&mid=<? echo $mid; ?>&smid=<? echo $smid; ?>"><input type="button" name="calcle" value="Cancel" /></a>
				</td> 				
			</tr>
		</table>
</div>
</div>
</div>	
</form>
</body>
</html>